<template>
  <div class="login">
    <el-dialog
      :close-on-click-modal="params.closeModal"
      :close-on-press-escape="params.closeEsc"
      :modal="params.modal"
      :show-close="params.showClose"
      :title="params.title"
      :visible.sync="params.dialogVisible"
      width="30%"
    >
      <el-form
        :label-position="labelPosition"
        :model="form"
        label-width="80px"
        ref="form"
      >
        <el-form-item label="用户名">
          <el-input v-model="form.userName"></el-input>
        </el-form-item>
        <el-form-item label="密码">
          <el-input show-password v-model="form.password"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button @click="onSubmit" size="medium" type="primary"
            >登陆
          </el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import MyDialogV1 from "@/common/dialogV1/index";
import * as server from "@/api/login";

export default {
  name: "login",
  data() {
    return {
      params: {
        data: "",
        title: "登陆",
        dialogVisible: true,
        modal: false, //遮罩层
        closeModal: false, //点击遮罩层关闭弹窗
        showClose: false, //显示关闭按钮
        closeEsc: false, //是否可以通过esc关闭
        showBtn: false
      },
      labelPosition: "right",
      form: {
        userName: "admin",
        password: "123123"
      }
    };
  },
  components: {
    // eslint-disable-next-line vue/no-unused-components
    "My-dialogV1": MyDialogV1
  },
  methods: {
    onSubmit() {
      //登陆
      server.loginUser(this.form).then(response => {
        //设置token
        if (response.state === 1 && response.entity) {
          this.$store.state.token = response.entity;
          server.path().then(() => {
            //跳转路由
            this.$router.push({ name: "首页" });
          });
        } else {
          alert("网络异常，请稍后再试！");
        }
      });
    }
  }
};
</script>

<style scoped>
.login {
  /*background: url("../../assets/Three_Kingdoms_2.jpg") no-repeat;*/
  background-color: aliceblue;
  background-size: 100% 100%;
  -moz-background-size: 100% 100%;
  width: 100%;
  height: 100%;
}
</style>
